<!--
描述：直播模块-直播视频
开发人：zhaohang
开发日期：2019年12月25日
-->
<template lang="pug">
  keep-alive
    kalix-table(bizKey="liveVideo" title='直播视频' ref="kalixTable"
    v-bind:tableFields="tableFields"
    v-bind:targetURL="liveVideoURL"
    v-bind:bizDialog="liveVideoDialog"
    v-bind:btnList="liveVideoBtnList"
    v-bind:buttonPermissionPrefix="buttonPermissionPrefix"
    v-bind:toolbarBtnList="toolbarBtnList"
    v-bind:customRender="showChapter"
    bizSearch="liveVideoSearch")
      template(slot="tableColumnSlot")
        el-table-column(prop="name" label="课程名称" align="center")
        el-table-column(prop="teacher" label="教师名称" align="center")
        el-table-column(prop="classIntroduce" label="课程简介" align="center")
          template(slot-scope="scope")
            span {{scope.row.classIntroduce | ellipsis}}
        el-table-column(prop="video" label="视频" align="center")
          template(slot-scope="scope")
            span {{scope.row.video | changeStyle}}
</template>

<script type="text/ecmascript-6">
  import {liveVideoURL, liveVideoBtnPermissionPrefix} from '../../config.toml'
  import {liveVideoConfigBtnList} from './config'
  import KalixTable from '../../../../../components/corelib/components/common/baseTable'

  export default {
    filters: {
      ellipsis(value) {
        if (!value) return ''
        if (value.length > 8) {
          return value.slice(0, 8) + '...'
        }
        return value
      },
      changeStyle (value) {
        if (!value) return ''
        if (value.length > 0) {
          value = value.substring(value.lastIndexOf('/') + 1, value.length)
        }
        return value
      }
    },
    name: 'kalix-mplive-livevideo',
    components: {KalixTable},
    data() {
      return {
        liveVideoURL: liveVideoURL,
        tableFields: [
          {prop: 'name', label: '课程名称'},
          {prop: 'teacher', label: '老师名称'},
          {prop: 'classIntroduce', label: '课程简介'},
          {prop: 'video', label: '视频'}
        ],
        liveVideoDialog: [
          {id: 'add', dialog: 'liveVideoAdd'},
          {id: 'edit', dialog: 'liveVideoEdit'},
          {id: 'view', dialog: 'liveVideoView'}
        ],
        liveVideoBtnList: liveVideoConfigBtnList,
        buttonPermissionPrefix: liveVideoBtnPermissionPrefix,
        toolbarBtnList: [
          {id: 'add', isShow: true, title: '添加', isPermission: true}
        ]
      }
    },
    methods: {
      showChapter(_data) {
        if (_data) {
          _data.forEach((e) => {
            if (e.video != null) {
              // 视频文件路径
              e.videoName = e.video
              let str0 = e.videoName
              e.videoName = str0.substring(str0.lastIndexOf('/') + 1, str0.length)
            }
          })
        }
      }
    }
  }
</script>

<style scoped lang="stylus">

</style>
